package com.example.esdemo.entity;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * 给ES用，强调的是哪些位置需要被搜索
 */
@Data
@Document(indexName = "book")
public class ESBook {
    @Id
    @Field(type= FieldType.Text)
    private String id;

    /*
    报错：object mapping for [title] tried to parse field [title] as object
    查看映射关系： curl -X GET "http://localhost:9200/book/_mapping?pretty"
    直接用浏览器打开 http://localhost:9200/book/_mapping?pretty
    怎么删除document： curl -X DELETE "http://localhost:9200/book"

    报错：analyzer [ik_max_word] has not been configured in mappings
    分词器没有装
     */

    @Field(type=FieldType.Text)
    private String title;
    @Field(type=FieldType.Text)
    private String author;

    @Field(type=FieldType.Double)
    private Object price;

    @Field(type=FieldType.Date,format = DateFormat.basic_date_time)
    private Date creatTime;

    @Field(type=FieldType.Date,format = DateFormat.basic_date_time)
    private Date updateTime;
}
